<?
require_once(dirname(__FILE__).'/../models/Orders.php');
require_once(dirname(__FILE__).'/../models/OrdersDetails.php');
require_once(dirname(__FILE__).'/../models/OrdersStatusesChanges.php');

class OrdersController extends Main_Controller_Action {	
	public function preDispatch()
    {
        if (!unserialize(Zend_Auth::getInstance()->getIdentity())->getIsAdministrator()) {        
                $this->_helper->redirector('', '');
        } else {
           /**
			 * Translation - Loading dictionaries common and backoffice_common
			 */
			$commonLocale = Translator::loadTranslation($this->currentLang, 'common');
			$this->view->commonLocale = $commonLocale;
        }
    }
    
	function indexAction(){
		
		if (intval($this->getRequest()->getParam('statusesId')) > 0){
			$filter = "WHERE last_statuses_id = ".intval($this->getRequest()->getParam('statusesId'));
		} else {
			$filter = "";
		}
		
		$orderBy = "ORDER BY id DESC";
		try{
			
			$orders = ModelMapper::instance('Orders')->findFiltered($filter, $orderBy);
		} catch (DatabaseException $e){
				$e->getMessage();
		}

		splitOrders($orders);
					
		$this->view->orders = $orders;
		
		//debug($this->getRequest()->getParam('statusesId'));
	}
}

?>